package v1

import (
	"gin_cli/models"
	"gin_cli/pkg/e"
	"gin_cli/pkg/lgz"
	"gin_cli/pkg/util"
	"net/http"
	"strconv"

	"github.com/astaxie/beego/validation"
	"github.com/gin-gonic/gin"
)

type Test struct {
}

func (this *Test) GetList(c *gin.Context) {
	valid := validation.Validation{}
	page := c.DefaultQuery("page", "1")
	pageInt, _ := strconv.Atoi(page)

	valid.Min(pageInt, 1, "page").Message("最小参数为1")
	// 参数验证
	if result, err := util.Validate(valid); err != nil {
		c.JSON(
			http.StatusOK,
			e.GetResponse(e.INVALID_PARAMS, result),
		)
		c.Abort()
		return
	}
	where := make(map[string]interface{})
	where["name"] = "灿灿"
	//data := new(models.Tag).GetList(map[string]interface{}{})
	data := new(models.Tag).GetList(where)
	c.JSON(
		http.StatusOK,
		e.GetResponse(e.SUCCESS, data),
	)
	return
}
func (this *Test) Add(c *gin.Context) {
	// pagination := util.GetPagination(c)
	// fmt.Println("pagination", pagination)
	// where := make(map[string]interface{})
	// // where["status"]=
	// rows, _ := new(models.Device).GetList(where, pagination)
	// data := make(map[string]interface{})
	// data["rows"] = rows
	// data["count"] = count
	//service.GetWechatUserInfo("oCTmUwG5WpHq2UPT-fdOuypjkoa4")
	token, _ := lgz.LgzSDK.GetAccessToken()
	c.JSON(
		http.StatusOK,
		e.GetResponse(e.SUCCESS, token),
	)
}
